package com.jianying.day10;

import org.apache.flink.api.common.eventtime.WatermarkStrategy;
import org.apache.flink.api.common.serialization.SimpleStringSchema;
import org.apache.flink.connector.kafka.source.KafkaSource;
import org.apache.flink.connector.kafka.source.enumerator.initializer.OffsetsInitializer;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.kafka.clients.consumer.ConsumerConfig;

/**
 * ClassName: Flink02_2pc_source
 * Package: com.atguigu.day10
 * Description:
 *
 * @Author: tubage
 * @Create: 2024/4/12 10:36
 * @Version: 1.0
 */
public class Flink02_2pc_source {
    public static void main(String[] args) throws Exception {
        // TODO 从kafka读数据
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        KafkaSource<String> kafkaSource = KafkaSource.<String>builder()
                .setBootstrapServers("localhost:9092,localhost:9093,localhost:9094")
                .setTopics("first")
                .setGroupId("test")
                .setStartingOffsets(OffsetsInitializer.latest())
                .setValueOnlyDeserializer(new SimpleStringSchema())
                .setProperty(ConsumerConfig.ISOLATION_LEVEL_CONFIG, "read_committed" ) // TODO 1 消费端设置隔离级别
                .build();

        env.fromSource(kafkaSource, WatermarkStrategy.noWatermarks(), "kafkaSource")
                .print();

        env.execute();
    }
}
